#include "delete_.h"
#include "ui_delete_.h"

delete_::delete_(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::delete_)
{
    ui->setupUi(this);
    setFixedSize(400, 174);
}

delete_::~delete_()
{
    delete ui;
}

void delete_::set_type(int a)
{
    type=a;
}

void delete_::on_pushButton_clicked()    //back按钮点击触发
{
    this->close();
}

void delete_::on_pushButton_2_clicked()  //delete按钮点击触发
{
    QString no;
    no=ui->textEdit->toPlainText();
    QSqlQuery query;
    if(type==0)  //删除学生信息
    {
        query.exec("delete from s_c where sno='"+no+"'");     //删除选课表中该学生的信息
        query.exec("delete from student where sno='"+no+"'"); //删除学生信息
    }
    else if(type==1)  //删除教师信息
    {
        QString cno;
        query.exec("select cno from teacher where tno='"+no+"'"); //获取该老师所授课程号
        query.next();
        cno=query.value(0).toString();
        query.exec("delete from s_c where cno='"+cno+"'");        //删除选课表中此课程的选课信息
        query.exec("delete from teacher where tno='"+no+"'");     //删除该老师
    }
    else if(type==2)  //删除课程信息
    {
        query.exec("delete from s_c where cno='"+no+"'");    //删除选课表中此课程的选课信息
        query.exec("delete from course where cno='"+no+"'"); //删除课程信息
    }
    QMessageBox::about(NULL,"tip","delete successful!"); //提示框：删除成功
    ui->textEdit->setText("");  //将文本框置空

}
